import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export type DefaultConfig = PowerPartial<EggAppConfig>;

export default (appInfo: EggAppInfo) => {
  const config = {} as DefaultConfig;
  // mysql 数据库
  config.orm = {
    type: 'mysql',
    host: '127.0.0.1',
    port: '3306',
    username: 'root',
    password: 'root123',
    database: 'midway',
    synchronize: true,
    logging: false,
  };
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1635985520826_3439';
  config.axiso = {
    baseURL: '',
    headers: {},
  };

  // redis
  config.redis = {
    client: {
      port: 6379, // Redis port
      host: '127.0.0.1', // Redis host
      password: '',
      db: 0,
    },
  };

  // 任务调度配置
  config.taskConfig = {
    redis: {
      port: 6379, // Redis port
      host: '127.0.0.1', // Redis host
      password: '',
    },
    prefix: 'midway-task',
    defaultJobOptions: {
      repeat: {
        tz: 'Asia/Shanghai', // Task等参数里面设置的比如（0 0 0 * * *）本来是为了0点执行，但是由于时区不对，所以国内用户时区设置一下。
      },
    },
  };

  // jwt
  config.jwt = {
    secret: '123456',
    enable: false,
    ignore: ['/sign'],
  };

  // add your config here
  config.middleware = [];

  config.midwayFeature = {
    // true 代表使用 midway logger
    // false 或者为空代表使用 egg-logger
    replaceEggLogger: true,
  };

  // config.security = {
  //   csrf: false,
  // };

  return config;
};
